package codeGen.core.model;

import java.util.List;


public class TableModel {
    //表名称
    private String name;
    //根据表名生成的实体类名称
    private String toClassName;
    //根据表名生成的实体实例名称
    private String toEntityName;
    //表别名,用于controller中生成简短的访问路径,如：/administration/alias/list.do
    private String alias;
    private List<FieldModel> primtives;
    private List<FieldModel> fields;
    //是否有自增字段
    private Boolean hasFieldAutoIncrease = false;
    //自增字段名称
    private String fieldAutoIncrease;
    //主键字段名称
    private String fieldPrime;
    //是否有复合主键
    private Boolean hasCompositePk = false;
    //主键参数字符串，如：String username,String password
    private String fieldPrimeParamString;
    //用于INSERT语句的字段字符串,如：username,password,email
    private String fieldString;
    //用于INSERT语句的字段参数字符串,如：#{username},#{password},#{email}
    private String fieldWrapString;
    //主键类型
    private String primeType;
    //主键类型（小写）
    private String primeTypeLowerCase;
    //主键自增类型
    private String primeAutoIncreaseType;
    //分页类
    private String pagerType;

    public String getFieldPrimeParamString() {
        StringBuffer buf = new StringBuffer();
        for (FieldModel fm : primtives) {
            buf.append(fm.getJavaType()).append(" ").append(fm.getName()).append(",");
        }
        if (buf.length() > 0)
            buf.deleteCharAt(buf.length() - 1);
        return buf.toString();
    }

    public String getFieldString() {
        StringBuffer buf = new StringBuffer();
        for (FieldModel fm : fields) {
            if (!fm.getIsAutoIncrease()) {
                buf.append(fm.getName()).append(",");
            }
        }
        if (buf.length() > 0)
            buf.deleteCharAt(buf.length() - 1);
        return buf.toString();
    }

    public String getFieldWrapString() {
        StringBuffer buf = new StringBuffer();
        for (FieldModel fm : fields) {
            if (!fm.getIsAutoIncrease()) {
                buf.append("#{").append(fm.getName()).append("}").append(",");
            }
        }
        if (buf.length() > 0)
            buf.deleteCharAt(buf.length() - 1);
        return buf.toString();
    }

    public Boolean getHasCompositePk() {
        return hasCompositePk;
    }

    public void setHasCompositePk(Boolean hasCompositePk) {
        this.hasCompositePk = hasCompositePk;
    }

    public String getFieldPrime() {
        return fieldPrime;
    }

    public void setFieldPrime(String fieldPrime) {
        this.fieldPrime = fieldPrime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getToClassName() {
        return toClassName;
    }

    public void setToClassName(String toClassName) {
        this.toClassName = toClassName;
    }

    public String getToEntityName() {
        return toEntityName;
    }

    public void setToEntityName(String toEntityName) {
        this.toEntityName = toEntityName;
    }

    public List<FieldModel> getPrimtives() {
        return primtives;
    }

    public void setPrimtives(List<FieldModel> primtives) {
        this.primtives = primtives;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public List<FieldModel> getFields() {
        return fields;
    }

    public void setFields(List<FieldModel> fields) {
        this.fields = fields;
    }

    public Boolean getHasFieldAutoIncrease() {
        return hasFieldAutoIncrease;
    }

    public void setHasFieldAutoIncrease(Boolean hasFieldAutoIncrease) {
        this.hasFieldAutoIncrease = hasFieldAutoIncrease;
    }

    public String getFieldAutoIncrease() {
        return fieldAutoIncrease;
    }

    public void setFieldAutoIncrease(String fieldAutoIncrease) {
        this.fieldAutoIncrease = fieldAutoIncrease;
    }

    public String getPrimeType() {
        return primeType;
    }

    public void setPrimeType(String primeType) {
        this.primeType = primeType;
    }

    public String getPrimeTypeLowerCase() {
        return primeTypeLowerCase;
    }

    public void setPrimeTypeLowerCase(String primeTypeLowerCase) {
        this.primeTypeLowerCase = primeTypeLowerCase;
    }

    public String getPagerType() {
        return pagerType;
    }

    public void setPagerType(String pagerType) {
        this.pagerType = pagerType;
    }

    public String getPrimeAutoIncreaseType() {
        return primeAutoIncreaseType;
    }

    public void setPrimeAutoIncreaseType(String primeAutoIncreaseType) {
        this.primeAutoIncreaseType = primeAutoIncreaseType;
    }
}
